[Bug Fix] Accordion: hide closed content properly instead of zero height (#168)#433
Conversation
…ght (#168) Closed accordion content was rendered with height:0 + overflow-hidden, which trapped form field errors in an invisible, still-focusable region. Now the content element receives the `hidden` attribute after the close animation completes (and `data-state="closed"`), fully removing it from layout and form focus. On open, `hidden` is removed before the height animation begins. Animation remains smooth via motion.
There was a problem hiding this comment.
1 issue found across 3 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Rename `test_open_content_does_not_have_hidden` to `test_open_item_wires_stimulus_open_value`, add a `Visible content` assertion, and clarify comments to accurately describe that the hidden attribute is removed at JS runtime (not server-render time). Addresses code-review finding from cubic (confidence 9). Also rebuild mcp/data/registry.json to include the accordion_content.rb and accordion_controller.js changes from this PR so CI "MCP registry up to date" passes.
|
Addressed the code-review finding from cubic (confidence 9):
|
Closes #168
How to reproduce
FormFieldwith aFormFieldErrorinside a closedAccordionItem.height: 0withoverflow: hidden, so the error message can't be seen and the browser cannot scroll to / focus the invalid field.What changed
Before:
AccordionContentstarted withstyle="height: 0px;"andoverflow-y-hidden. The Stimulus controller only animated height between0andscrollHeight. The element was always in the layout (and form-focus) tree, just visually hidden.After:
AccordionContentnow renders withhiddenattribute anddata-state="closed"by default, completely removing it from layout and form-focus.accordion_controller.js) now:hiddenand setsdata-state="open"before animating height, soscrollHeightis measurable.0, then calls.finished.then(...)to sethiddenafter the animation completes (guarded bydata-state === "closed"to avoid racing a rapid re-open).motionlibrary and existing duration/easing values are unchanged.AccordionContent,AccordionItem,AccordionTrigger, targets, and values are all preserved.Testing instructions
Automated tests
Manual browser verification
AccordionContent— verify it hashiddenattribute anddata-state="closed".hiddenis removed,data-statebecomes"open", and the animation is smooth.0, thenhiddenreappears on the element.<input required>and an error<span>inside a closedAccordionContent, submit the form empty, then open the accordion — confirm the validation error is visible and the field is focusable.Summary by cubic
Fixes the Accordion so closed content is truly removed from layout and focus using the
hiddenattribute instead ofheight: 0clipping. Prevents invisible validation errors while keeping open/close animations smooth.AccordionContentnow renders withhiddenanddata-state="closed".hidden, setdata-state="open", then animate to measured height.height: 0, then sethidden; guarded bydata-stateto avoid races.mcp/data/registry.jsonfor CI; public API unchanged.Written for commit 837712f. Summary will update on new commits.